package com.example.petstore_2.config;

import com.example.petstore_2.config.Handler;
import com.example.petstore_2.aspect.JWTInterceptors;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new Handler()).addPathPatterns("/**");
        registry.addInterceptor(new JWTInterceptors())
                .addPathPatterns("/user/test")  // 需要验证jwt的路径
                .addPathPatterns("/cartItems/{itemId}")
                .addPathPatterns("/cartItems")
                .addPathPatterns("/messages")
                .addPathPatterns("/closeChat")
                .addPathPatterns("/orders")
                .addPathPatterns("/noShipOrders")
                .addPathPatterns("/shipOrders")
                .addPathPatterns("/noPayOrders")
                .addPathPatterns("/noGetOrders")
                .addPathPatterns("/orders/{orderId}")
                .addPathPatterns("/lineItems/order/{orderId}")
                .addPathPatterns(("/orders/buyNow"))
                .addPathPatterns("/user/newOrder")
                .addPathPatterns("/qrCode/{orderId}")
                .addPathPatterns("/user/finishPay")
                .addPathPatterns("/payStatus/{orderId}")
                .addPathPatterns("/returnOrders/{orderId}")
                .addPathPatterns("/orders/pay/{outTradeNo}")
                .addPathPatterns("/cancelOrders/{orderId}")
                .addPathPatterns("/orders/<orderId>")
                .excludePathPatterns("/user/loginByName")  // 所有用户都放行
                .excludePathPatterns("/categorys/{category}")
                .excludePathPatterns("/alipay/**")
                .excludePathPatterns("/categorys");
    }
}
